home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_md5.h.z / apr_md5.h
C/C++ Source or Header  |  2002-07-08  |  7KB  |  188 lines

  1. /*
  2.  * This is work is derived from material Copyright RSA Data Security, Inc.
  3.  *
  4.  * The RSA copyright statement and Licence for that original material is
  5.  * included below. This is followed by the Apache copyright statement and
  6.  * licence for the modifications made to that material.
  7.  */
  8.  
  9. /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  10.    rights reserved.
  11.  
  12.    License to copy and use this software is granted provided that it
  13.    is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  14.    Algorithm" in all material mentioning or referencing this software
  15.    or this function.
  16.  
  17.    License is also granted to make and use derivative works provided
  18.    that such works are identified as "derived from the RSA Data
  19.    Security, Inc. MD5 Message-Digest Algorithm" in all material
  20.    mentioning or referencing the derived work.
  21.  
  22.    RSA Data Security, Inc. makes no representations concerning either
  23.    the merchantability of this software or the suitability of this
  24.    software for any particular purpose. It is provided "as is"
  25.    without express or implied warranty of any kind.
  26.  
  27.    These notices must be retained in any copies of any part of this
  28.    documentation and/or software.
  29.  */
  30.  
  31. /* ====================================================================
  32.  * The Apache Software License, Version 1.1
  33.  *
  34.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  35.  * reserved.
  36.  *
  37.  * Redistribution and use in source and binary forms, with or without
  38.  * modification, are permitted provided that the following conditions
  39.  * are met:
  40.  *
  41.  * 1. Redistributions of source code must retain the above copyright
  42.  *    notice, this list of conditions and the following disclaimer.
  43.  *
  44.  * 2. Redistributions in binary form must reproduce the above copyright
  45.  *    notice, this list of conditions and the following disclaimer in
  46.  *    the documentation and/or other materials provided with the
  47.  *    distribution.
  48.  *
  49.  * 3. The end-user documentation included with the redistribution,
  50.  *    if any, must include the following acknowledgment:
  51.  *       "This product includes software developed by the
  52.  *        Apache Software Foundation (http://www.apache.org/)."
  53.  *    Alternately, this acknowledgment may appear in the software itself,
  54.  *    if and wherever such third-party acknowledgments normally appear.
  55.  *
  56.  * 4. The names "Apache" and "Apache Software Foundation" must
  57.  *    not be used to endorse or promote products derived from this
  58.  *    software without prior written permission. For written
  59.  *    permission, please contact apache@apache.org.
  60.  *
  61.  * 5. Products derived from this software may not be called "Apache",
  62.  *    nor may "Apache" appear in their name, without prior written
  63.  *    permission of the Apache Software Foundation.
  64.  *
  65.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  66.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  67.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  68.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  69.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  70.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  71.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  72.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  73.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  74.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  75.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  76.  * SUCH DAMAGE.
  77.  * ====================================================================
  78.  *
  79.  * This software consists of voluntary contributions made by many
  80.  * individuals on behalf of the Apache Software Foundation.  For more
  81.  * information on the Apache Software Foundation, please see
  82.  * <http://www.apache.org/>.
  83.  */
  84.  
  85. #ifndef APR_MD5_H
  86. #define APR_MD5_H
  87.  
  88. #include "apr.h"
  89. #include "apr_xlate.h"
  90.  
  91. #ifdef __cplusplus
  92. extern "C" {
  93. #endif
  94. /**
  95.  * @file apr_md5.h
  96.  * @brief APR MD5 Routines
  97.  */
  98.  
  99. /**
  100.  * @defgroup APR_MD5 MD5 Routines
  101.  * @ingroup APR
  102.  * @{
  103.  */
  104.  
  105. #define MD5_DIGESTSIZE 16
  106.  
  107. typedef struct apr_md5_ctx_t apr_md5_ctx_t;
  108.  
  109. /** MD5 context. */
  110. struct apr_md5_ctx_t {
  111.     /** state (ABCD) */
  112.     apr_uint32_t state[4];
  113.     /** number of bits, modulo 2^64 (lsb first) */
  114.     apr_uint32_t count[2];
  115.     /** input buffer */
  116.     unsigned char buffer[64];
  117. #if APR_HAS_XLATE
  118.     /** translation handle */
  119.     apr_xlate_t *xlate;
  120. #endif
  121. };
  122.  
  123. /**
  124.  * MD5 Initialize.  Begins an MD5 operation, writing a new context.
  125.  * @param context The MD5 context to initialize.
  126.  */
  127. APR_DECLARE(apr_status_t) apr_md5_init(apr_md5_ctx_t *context);
  128.  
  129. /**
  130.  * MD5 translation setup.  Provides the APR translation handle to be used 
  131.  * for translating the content before calculating the digest.
  132.  * @param context The MD5 content to set the translation for.
  133.  * @param xlate The translation handle to use for this MD5 context 
  134.  */
  135. #if APR_HAS_XLATE
  136. APR_DECLARE(apr_status_t) apr_md5_set_xlate(apr_md5_ctx_t *context,
  137.                                             apr_xlate_t *xlate);
  138. #else
  139. #define apr_md5_set_xlate(context, xlate) APR_ENOTIMPL
  140. #endif
  141.  
  142. /**
  143.  * MD5 block update operation.  Continue an MD5 message-digest operation, 
  144.  * processing another message block, and updating the context.
  145.  * @param context The MD5 content to update.
  146.  * @param input next message block to update
  147.  * @param inputLen The length of the next message block
  148.  */
  149. APR_DECLARE(apr_status_t) apr_md5_update(apr_md5_ctx_t *context,
  150.                                          const unsigned char *input,
  151.                                          apr_size_t inputLen);
  152.  
  153. /**
  154.  * MD5 finalization.  Ends an MD5 message-digest operation, writing the 
  155.  * message digest and zeroing the context
  156.  * @param digest The final MD5 digest
  157.  * @param context The MD5 content we are finalizing.
  158.  */
  159. APR_DECLARE(apr_status_t) apr_md5_final(unsigned char digest[MD5_DIGESTSIZE],
  160.                                         apr_md5_ctx_t *context);
  161.  
  162. /**
  163.  * MD5 in one step
  164.  * @param digest The final MD5 digest
  165.  * @param input The message block to use
  166.  * @param inputLen The length of the message block
  167.  */
  168. APR_DECLARE(apr_status_t) apr_md5(unsigned char digest[MD5_DIGESTSIZE],
  169.                                   const unsigned char *input,
  170.                                   apr_size_t inputLen);
  171.  
  172. /**
  173.  * Encode a password using an MD5 algorithm
  174.  * @param password The password to encode
  175.  * @param salt The salt to use for the encoding
  176.  * @param result The string to store the encoded password in
  177.  * @param nbytes The length of the string
  178.  */
  179. APR_DECLARE(apr_status_t) apr_md5_encode(const char *password, const char *salt,
  180.                                          char *result, size_t nbytes);
  181.  
  182. /** @} */
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186.  
  187. #endif /* !APR_MD5_H */
  188.